<template>
	<view class="nething_address" v-show="Object.keys(addressData).length == 0" @click="getAddressNow">
		<button type="primary" >点击获取收获地址</button>
	</view>
	<view class="address_list" v-show="Object.keys(addressData).length > 0"  @click="getAddressNow">
		<view class="address_list_toper">
			<text class="address_name">收货人:{{addressData.userName}}</text>
			<view >
				<text class="address_phone">电话:{{addressData.telNumber}}</text>
				<uni-icons type="right" size="35rpx" style="margin-left: 10rpx;"></uni-icons>
			</view>
		</view>
		<view class="address_main">
			收货地址: {{fullName}}
		</view>
	</view>
</template>

<script>
	import {mapState,mapMutations,useStore } from 'vuex'
	import {
		defineComponent,
		reactive,
		toRefs,
		watch,
		computed,
		inject
	} from 'vue'
	import {
		onReachBottom,
		onShow,
		onLoad,
		onPullDownRefresh
	} from '@dcloudio/uni-app';
	import {getAddress} from '../../Tools/toolsSum.js'
	export default defineComponent({
		name:'address',
		setup(){
			const datas = reactive({
				addressData:getAddress()
			})
			const fullName = computed(()=>{
				if(!datas.addressData)return
				let fullName = ''
				let key = Object.keys(datas.addressData)
				key.map(item =>{
					switch(item){
						case "provinceName" :
						fullName += datas.addressData[item]
						break
						case "cityName" :
						fullName += datas.addressData[item]
						break
						case "countyName" :
						fullName += datas.addressData[item]
						break
						case 'detailInfo':
						fullName += datas.addressData[item]
						break
					}
				})
				return fullName
			})
			async function getAddressNow(){
				try{
					const result = await uni.chooseAddress()
					uni.setStorageSync('addressData',JSON.stringify(result))
					datas.addressData = result
					
				}catch(err){
					uni.showModal({
						cancelText:'是的',
						content:"检测到您取消地址的获取,您确定吗?",
						confirmText:'重选',
						success(res){
							res.confirm ? getAddressNow() : ''
						}
					})
				}
			}
			return {
				getAddressNow,...toRefs(datas),fullName
			}
		}
	})
</script>

<style lang="less">
.nething_address{
	height: 200rpx;
	display: flex;
	justify-content: center;
	align-items: center;
	
}
.address_list{
	display: flex;
	flex-direction: column;
	justify-content: center;
	font-size: 27rpx;
	height: 200rpx;
	padding:0 10rpx;
	.address_list_toper{
		margin-bottom: 20rpx;
		
		display: flex;
		justify-content: space-between;
	}
}
</style>
